package com.woniuxy.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.woniuxy.DTO.AddAlgsFeedingRecordDTO;
import com.woniuxy.DTO.AlgsFeedingRecordDTO;
import com.woniuxy.service.IAlgsStaffService;
import com.woniuxy.service.IAlgsTypeService;
import com.woniuxy.util.ResultVO;
import com.woniuxy.vo.AlgsFeedingRecirdVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.woniuxy.domain.AlgsFeedingRecord;
import com.woniuxy.service.IAlgsFeedingRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 饲养记录Controller
 * 
 * @author ruoyi
 * @date 2023-03-15
 */
@RestController
@RequestMapping("/feedingRecord")
public class AlgsFeedingRecordController extends BaseController
{
    @Autowired
    private IAlgsFeedingRecordService algsFeedingRecordService;
    @Autowired
    private IAlgsStaffService iAlgsStaffService;
    @Autowired
    private IAlgsTypeService iAlgsTypeService;
    /**
     * 查询饲养记录列表(员工)
     */
   // @RequiresPermissions("feedingRecord:feedingRecord:list")
    @GetMapping("/list")
    public AjaxResult queryAllByFeedingRecord(AlgsFeedingRecordDTO algsFeedingRecordDTO){
        List<AlgsFeedingRecirdVO> algsFeedingRecirdVOS = algsFeedingRecordService.queryAlgsFeedingRecordAndTypeMsgAndStaffName(algsFeedingRecordDTO);

        return AjaxResult.success(algsFeedingRecirdVOS);
    }



    /**
     * 导出饲养记录列表
     */
   // @RequiresPermissions("feedingRecord:feedingRecord:export")
    @Log(title = "饲养记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgsFeedingRecord algsFeedingRecord)
    {
        List<AlgsFeedingRecord> list = algsFeedingRecordService.selectAlgsFeedingRecordList(algsFeedingRecord);
        ExcelUtil<AlgsFeedingRecord> util = new ExcelUtil<AlgsFeedingRecord>(AlgsFeedingRecord.class);
        util.exportExcel(response, list, "饲养记录数据");
    }

    /**
     * 提交饲养记录
     */
   // @RequiresPermissions("feedingRecord:feedingRecord:query")
    @GetMapping("/{feedingRecordId}")
    public AjaxResult getInfo(@PathVariable("feedingRecordId") Long feedingRecordId)
    {
        AlgsFeedingRecord algsFeedingRecord = new AlgsFeedingRecord();
        algsFeedingRecord.setTypeId(63L);
        algsFeedingRecord.setFeedingRecordId(feedingRecordId);
        return success(algsFeedingRecordService.updateAlgsFeedingRecord(algsFeedingRecord));
    }

    /**
     * 新增饲养记录
     */
   // @RequiresPermissions("feedingRecord:feedingRecord:add")
    @Log(title = "饲养记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgsFeedingRecord algsFeedingRecord)
    {
        System.out.println(algsFeedingRecord);
        return toAjax(algsFeedingRecordService.insertAlgsFeedingRecord(algsFeedingRecord));
    }

    /**
     * 查询饲养部所有员工的姓名
     */
   // @RequiresPermissions("feedingRecord:feedingRecord:queryAllFeedingRecordName")
    @GetMapping("/queryAllFeedingRecordName")
    public AjaxResult queryAllStaffNameInFeedingRecord()
    {
        return success(iAlgsStaffService.selectAllStaffName());
    }
    /**
     * 查询全部饲养状态
     */
  //  @RequiresPermissions("feedingRecord:feedingRecord:queryTypeFeedingRecord")
    @GetMapping("/queryTypeFeedingRecord")
    public AjaxResult queryTypeFeedingRecord()
    {
        return success(iAlgsTypeService.selectAllTypeMsg());
    }
    /**
     * 查询全部饲养状态(管理)
     */
    @GetMapping("/FeedingRecordManger")

    public AjaxResult listFeedingRecordManger(AlgsFeedingRecordDTO algsFeedingRecordDTO){
        List<AlgsFeedingRecirdVO> algsFeedingRecirdVOS = algsFeedingRecordService.queryAlgsFeedingRecordAndTypeMsgAndStaffNameManger(algsFeedingRecordDTO);

        return AjaxResult.success(algsFeedingRecirdVOS);
    }
    /**
     * 管理已读饲养记录
     */
    // @RequiresPermissions("feedingRecord:feedingRecord:query")
    @GetMapping(value = "FeedingRecordReading{feedingRecordId}")
    public AjaxResult FeedingRecordReading(@PathVariable Long feedingRecordId)
    {
        System.out.println(feedingRecordId);
        AlgsFeedingRecord algsFeedingRecord = new AlgsFeedingRecord();

        algsFeedingRecord.setTypeId(64L);
        algsFeedingRecord.setFeedingRecordId(feedingRecordId);
        return success(algsFeedingRecordService.updateAlgsFeedingRecord(algsFeedingRecord));
    }
    /**
     * 管理归档饲养记录
     */
    // @RequiresPermissions("feedingRecord:feedingRecord:query")
    @GetMapping( "pigeonhole{feedingRecordId}")
    public AjaxResult pigeonhole(@PathVariable("feedingRecordId") Long feedingRecordId)
    {
        AlgsFeedingRecord algsFeedingRecord = new AlgsFeedingRecord();
        algsFeedingRecord.setTypeId(65L);
        algsFeedingRecord.setFeedingRecordId(feedingRecordId);
        return success(algsFeedingRecordService.updateAlgsFeedingRecord(algsFeedingRecord));
    }
}
